package main

import "fmt"

func print(name string, sl []int) {
	fmt.Printf("%s, len = %d, cap = %d\n", name, len(sl), cap(sl))
}

func main() {
	// 声明切片和数组类似，但不指定长度
	var nums = []int{1, 2, 3, 4, 5, 6}

	// 使用 append 向切片末尾添加元素
	nums = append(nums, 1)
	fmt.Println(len(nums))
	fmt.Println(nums)

	fmt.Println("-----------------------")

	var num2 = []int{}
	print("num2", num2)
	num2 = append(num2, 1)
	print("num2 after append", num2)
	num2 = append(num2, 2)
	print("num2 after append", num2)
	num2 = append(num2, 3)
	print("num2 after append", num2)
	num2 = append(num2, 4)
	print("num2 after append", num2)
	num2 = append(num2, 5)
	print("num2 after append", num2)
}
